package com.lanchetech.dao;

import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.request.RewardQueuePageReq;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.RewardQueue;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Mapper
public interface RewardQueueMapper {
    int deleteByPrimaryKey(Long id);

    int insert(RewardQueue record);

    int insertSelective(RewardQueue record);

    RewardQueue selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(RewardQueue record);

    int updateByPrimaryKey(RewardQueue record);

    RewardQueue findOneByLevelAndQueueStatusOrderByCreatedAt(@Param("level") Integer level, @Param("queueStatus") Byte queueStatus);

    WaitFreeVO getWaitFree(Integer level);

    List<UserSimpleVO> findTopByLevel(@Param("level") Integer level);

    List<UserSimpleVO> findAllByLevelAndQueueStatus(@Param("level") Integer level, @Param("queueStatus") Byte queueStatus, @Param("num") Long num);

    List<RewardQueueVO> findAllPage(PageReq req);

    List<RewardQueueVO> findAllRewardPage(RewardQueuePageReq req);

    int updateRewardStatusAndUpdateAtById(@Param("updatedRewardStatus") Byte updatedRewardStatus, @Param("updatedUpdateAt") Date updatedUpdateAt, @Param("id") Long id);

    RewardQueue findOneByUserIdAndQueueStatus(@Param("userId") Long userId, @Param("queueStatus") Byte queueStatus);

    RewardQueue findOneBySpuIdAndQueueStatusOrderByCreatedAt(@Param("spuId") Long spuId, @Param("queueStatus") Byte queueStatus);

    int updateQueueStatusByQueueStatusAndOrderSkuId(@Param("updatedQueueStatus") Byte updatedQueueStatus, @Param("queueStatus") Byte queueStatus, @Param("orderSkuId") Long orderSkuId);

    List<RewardQueueVO> getRewardQueue(@Param("rewardStatus") Byte rewardStatus, @Param("queueStatus") Byte queueStatus);

    Integer getAwardIncomeQueueNumber(@Param("date") Date date, @Param("type") Byte type, @Param("level") Integer level, @Param("queueStatus") Byte queueStatus);

    List<HistoryAwardVO> getHistoryAward(@Param("type") Byte type, @Param("level") Integer level, @Param("rewardStatus") Byte rewardStatus);

    List<RewardQueueLatelyVO> getRewardQueueLately(@Param("type") Byte type, @Param("level") Integer level);

    BigDecimal sumByUserIdAndQueueStatusAndRewardStatus(@Param("userId") Long userId, @Param("rewardStatus") Byte rewardStatus);

    RewardQueue findOneTopReward(@Param("rewardStatus") Byte rewardStatus);

    BigDecimal getFreeOrderMoney(@Param("id") Long id, @Param("rewardType") Byte rewardType);

    BigDecimal getNoFreeOrderMoney(@Param("id") Long id, @Param("rewardType") Byte rewardType);

    List<FreeOrderListVO> getFreeOrderPage(PageReq req);

    Integer getFreeOrderCurrentQueue(@Param("date") Date date, @Param("userId") Long userId, @Param("type") Byte type, @Param("spuId") Long spuId);

    Integer getNoFreeOrderCurrentQueue(@Param("date") Date date, @Param("userId") Long userId, @Param("type") Byte type, @Param("level") Integer level);

    Date getEarliestRewardQueue(@Param("userId") Long superiorId, @Param("type") Byte type, @Param("level") Integer level, @Param("queueStatus") Byte status);

    RewardQueue findOneByRewardTypeAndQueueStatusForReward(@Param("rewardType") Byte rewardType, @Param("queueStatus") Byte queueStatus);

    RewardQueue findOneByRewardTypeAndQueueStatusForCancel(@Param("rewardType") Byte rewardType, @Param("queueStatus") Byte queueStatus);

    RewardQueue findOneByOrderSkuIdAndRewardTypeAndQueueStatus(@Param("orderSkuId") Long orderSkuId, @Param("rewardType") Byte rewardType, @Param("queueStatus") Byte queueStatus);

    int updateBatchAudioUrl(List<RewardQueue> updateAudio);

    RewardQueue findOneByUserIdAndRewardTypeAndQueueStatusCreatedAtAsc(@Param("userId") Long userId, @Param("rewardType") Byte rewardType, @Param("queueStatus") Byte queueStatus);

    RewardQueue findOneByRewardTypeAndSpuIdAndUserIdAndRewardStatus(@Param("rewardType")Byte rewardType,@Param("spuId")Long spuId,@Param("userId")Long userId,@Param("rewardStatus")Byte rewardStatus);


}